<template>
  <div>
    <div class="login">
      <div class="login-header">
        <i class="iconfont icon-xiangzuojiantou" @click="$router.go('-1')"></i>
        <i class="iconfont icon-wenhaoxiao"></i>
      </div>
      <div class="login-title">
        <h1>密码登录</h1>
      </div>
      <div class="login-form">
        <div class="item">
          <div>
            <i class="iconfont icon-shouji3"></i>
            <input type="text" placeholder="手机号码" v-model="phone" />
          </div>
        </div>

        <div class="item">
          <div>
            <i class="iconfont icon-mima"></i>
            <input type="password" placeholder="密码" v-model="password" />
          </div>
        </div>

        <div class="item">
          <div class="submit" @click="submit">登录</div>
        </div>
      </div>
      <div class="login-other">
        <div class="other-top">
          <span>其他方式登录</span>
        </div>
        <div class="other-content">
          <svg>
            <use xlink:href="#icon-weixin1"></use>
          </svg>
          <svg>
            <use xlink:href="#icon-QQ"></use>
          </svg>
          <svg>
            <use xlink:href="#icon-weibo"></use>
          </svg>
          <svg>
            <use xlink:href="#icon-shouji1"></use>
          </svg>
        </div>
      </div>
      <div class="login-bottom">
        <div class="agreement">
          <input type="checkbox" :checked="checked" @click="check" />
          <span
            >登录注册即表示同意<a>《用户协议》</a>和<a>《隐私政策》</a></span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  data() {
    return {
      token: "",
      checked: false,
      phone: "",
      password: "",
    };
  },
  methods: {
    submit() {
      // 验证手机号码
      let regPhone =
        /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
      if (!regPhone.test(this.phone)) {
        Toast("请输入正确的信息");
        return;
      }
      // 验证密码
      let regPassword = /^[a-zA-Z]\w{5,17}$/;
      if (!regPassword.test(this.password)) {
        Toast("请输入正确的信息");
        return;
      }
      //验证手机号码
      if (this.checked == true) {
        let newList = {id:Date.now(),phone:this.phone,password:this.password};
        let list = JSON.parse(localStorage.getItem('token') || '[]');
        list.unshift(newList);

        localStorage.setItem('token',JSON.stringify(list));

        Toast("登录成功");

        this.$router.push("/info")
      } else {
        Toast("勾选确认用户协议和隐私政策");
      }
    },
    // login() {
    //   if (this.checked == true) {
    //     this.$router.push("/login");
    //   } else {
    //     Toast("勾选确认用户协议和隐私政策");
    //   }
    // },
    check() {
      this.checked = true;
    },
  },
};
</script>

<style lang="less">
.login {
  .login-header {
    height: 45px;
    line-height: 45px;
    margin-left: 20px;
    margin-right: 15px;
    display: flex;
    justify-content: space-between;
    i {
      font-size: 20px;
    }
    i:first-child {
      font-weight: bold;
    }
  }
  .login-title {
    margin: 35px 30px 80px;
    h1 {
      font-size: 26px;
      font-weight: bold;
    }
  }
  .login-form {
    .item {
      width: 76%;
      height: 30px;
      line-height: 30px;
      margin: 0 auto;
      margin-bottom: 15px;
      border-radius: 30px;
      background-color: #e4e4e4;
      input {
        border: 0;
        font-size: 14px;
        text-indent: 0.5em;
        color: #000;
        outline: none;
        background-color: transparent;
      }
      i {
        font-size: 18px;
        color: #1d1d1d;
        margin-left: 10px;
        vertical-align: middle;
        display: inline-block;
      }
      .submit {
        font-size: 15px;
        text-align: center;
        color: #eb3426;
        background-color: #e4e4e4;
        border-radius: 15px;
      }
    }
  }
  .login-other {
    margin-top: 100px;
    .other-top {
      margin: 0px 15px 0px 25px;
      span {
        font-size: 13px;
        font-weight: bold;
        color: #333;
        // color: #909090;
      }
    }
    .other-content {
      margin: 50px 15px 15px 25px;
      svg {
        width: 30px;
        height: 30px;
        margin: 0px 15px 0px 10px;
      }
    }
  }
  .login-bottom {
    margin-top: 80px;
    .agreement {
      margin: 30px 15px 0px 25px;
      display: flex;
      align-items: center;
      input {
        width: 12px;
        height: 12px;
        border-radius: 50%;
        margin: 0 5px;
      }
      span {
        font-size: 12px;
        color: #333;
        a {
          font-weight: bold;
          border-bottom: 1px solid #333;
        }
      }
    }
  }
}
</style>